package com.fengmi.service.impl;

import com.fengmi.entity.MallGoodsBrand;
import com.fengmi.mapper.MallGoodsBrandMapper;
import com.fengmi.service.MallGoodsBrandService;
import com.fengmi.vo.InfoResult;
import com.fengmi.vo.PageResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Author: 施俊豪
 * Date: 2022/1/17 17:48
 * Note:
 */
@Service
public class MallGoodsBrandServiceImpl implements MallGoodsBrandService {

    @Autowired(required = false)
    private MallGoodsBrandMapper mallGoodsBrandMapper;

    /**
     * @Note : 分页+条件查询商品品牌
     * @Date : 2022-01-17 17:56:42
     * @Author : 清酒吖
     * @throws
    */
    @Override
    public PageResult<MallGoodsBrand> findGoodsBrand(String pageNum, String pageSize, MallGoodsBrand mallGoodsBrand) {
        //分页查询
        PageHelper.startPage(Integer.parseInt(pageNum),Integer.parseInt(pageSize));
        //查询品牌列表
        List<MallGoodsBrand> goodsBrand = mallGoodsBrandMapper.findGoodsBrand(mallGoodsBrand);
        //返回pageInfo结果
        PageInfo<MallGoodsBrand> pageInfo = new PageInfo<>(goodsBrand);
        //将pageInfo结果映射到pageresult中
        PageResult<MallGoodsBrand> pageResult = new PageResult<>();
        pageResult.setTotal(pageInfo.getTotal());
        pageResult.setPages(pageInfo.getPages());
        pageResult.setPageList(pageInfo.getList());

        return pageResult;
    }


    /**
     * @Note : 添加商品品牌
     * @Date : 2022-01-18 09:45:21
     * @Author : 清酒吖
    */
    @Override
    public InfoResult addGoodsBrand(MallGoodsBrand mallGoodsBrand) {
        Integer row = mallGoodsBrandMapper.addGoodsBrand(mallGoodsBrand);
        InfoResult infoResult = new InfoResult();
        if(row>=1){
            infoResult.setSuccess(true);
            infoResult.setMsg("添加商品品牌成功!!!");
            infoResult.setData(row);
        }else {
            infoResult.setSuccess(false);
            infoResult.setMsg("添加商品品牌失败!!!");
            infoResult.setData(row);
        }
        return infoResult;
    }

    /**
     * @Note : 修改商品品牌信息
     * @Date : 2022-01-18 09:46:48
     * @Author : 清酒吖
    */
    @Override
    public InfoResult updateGoodsBrand(MallGoodsBrand mallGoodsBrand) {
        Integer row = mallGoodsBrandMapper.updateGoodsBrand(mallGoodsBrand);
        InfoResult infoResult = new InfoResult();
        if(row>=1){
            infoResult.setSuccess(true);
            infoResult.setMsg("修改商品品牌成功!!!");
            infoResult.setData(row);
        }else {
            infoResult.setSuccess(false);
            infoResult.setMsg("修改商品品牌失败!!!");
            infoResult.setData(row);
        }
        return infoResult;
    }

    @Override
    public InfoResult deleteGoodsBrand(Integer[] ids) {
        Integer row = mallGoodsBrandMapper.delGoodsBrand(ids);
        InfoResult infoResult = new InfoResult();
        if(row>=1){
            infoResult.setSuccess(true);
            infoResult.setMsg("删除商品品牌成功!!!");
            infoResult.setData(row);
        }else {
            infoResult.setSuccess(false);
            infoResult.setMsg("删除商品品牌失败!!!");
            infoResult.setData(row);
        }
        return infoResult;
    }

    /**
     * @Note : 查询所有商品品牌
     * @Date : 2022-01-20 17:37:36
     * @Author : 清酒吖
    */
    @Override
    public InfoResult<List<MallGoodsBrand>> findBrandAll(){
        List<MallGoodsBrand> brandList = mallGoodsBrandMapper.selectAll();
        return new InfoResult<List<MallGoodsBrand>> (true,"查询所有商品品牌成功！！！",brandList);
    }
}
